<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: black;
        }

        li {
            list-style: none;
        }

        a {
            text-decoration: none;
        }

        .nav {
            position: relative;
            margin: 100px auto;
            width: 900px;
            height: 42px;
            line-height: 42px;
            background: #fff url(./images/rss.png) no-repeat right center;
        }

        .nav ul {
            position: absolute;
            z-index: 1;
        }

        .nav ul li {
            margin: 0 10px;
            float: left;
        }

        .nav ul li a {
            color: black;
        }

        .nav ul li:first-of-type a {
            color: #0dff1d;
        }

        .nav ul li a:hover {
            color: white;
        }

        .cloud {
            position: absolute;
            left: 0;
            right: 0;
        }
    </style>

    <script src="./js/animate.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <nav class="nav">
        <!-- 移动背景 -->
        <img src="./images/cloud.gif" alt="" class="cloud">

        <!-- nav 内容 -->
        <ul class="nav-list">
            <li>
                <a href="javascript:;">首页新闻</a>
            </li>
            <li>
                <a href="javascript:;">师资力量</a>
            </li>
            <li>
                <a href="javascript:;">活动策划</a>
            </li>
            <li>
                <a href="javascript:;">企业文化</a>
            </li>
            <li>
                <a href="javascript:;">招聘信息</a>
            </li>
            <li>
                <a href="javascript:;">公司简介</a>
            </li>
            <li>
                <a href="javascript:;">我是佩奇</a>
            </li>
            <li>
                <a href="javascript:;">啥是佩奇</a>
            </li>
        </ul>
    </nav>

    <script>
        let navList = document.querySelector(".nav-list").children;
        let cloud = document.querySelector(".cloud");
        let navLen = navList.length;
        let current = 0;

        for (let i = 0; i < navLen; i++) {

            navList[i].addEventListener("mouseover", function () {
                animate(cloud, this.offsetLeft - 10, null);
            });

            navList[i].addEventListener("mouseleave", function () {
                animate(cloud, current, null);
            });

            navList[i].addEventListener("click", function () {
                current = this.offsetLeft - 10;

                for (let i = 0; i < navLen; i++) {
                    navList[i].children[0].style.color = "black";
                }

                this.children[0].style.color = "#0dff1d";
            });
        }
    </script>
</body>

</html>